var browser = new Object();

function getBrowser() {
	var b = navigator.userAgent.toLowerCase();
	browser = { 
		safari: /webkit/.test(b),
		opera: /opera/.test(b),
		ie6: /msie 6/.test(b) && !/opera/.test(b),
		ie7: /msie 7/.test(b) && !/opera/.test(b),
		msie: /msie/.test(b) && !/opera/.test(b),
		mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
	};
}
getBrowser();
function addClassName(oElm, strClassName){
	var strCurrentClass = oElm.className;
	if(!new RegExp(strClassName, "i").test(strCurrentClass)){
		oElm.className = strCurrentClass + ((strCurrentClass.length > 0)? " " : "") + strClassName;
	}
}

// --- by className
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];		
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}	
	}
	return (arrReturnElements)
}

// --- by AttributeValue
function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null;
	var oCurrent;
	var oAttribute;
	for(var i=0; i<arrElements.length; i++){
		oCurrent = arrElements[i];
		oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);
		if(typeof oAttribute == "string" && oAttribute.length > 0){
			if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
				arrReturnElements.push(oCurrent);
			}
		}
	}
	return arrReturnElements;
}

function removeClassName(oElm, strClassName){
	var oClassToRemove = new RegExp(('(^|\\s)' + strClassName + "($|\\s)"), "i");
	oElm.className = oElm.className.replace(oClassToRemove, "").replace(/^\s*|\s*$/g, "");
}
function applefish(extra , tfish , strTagName , oElm , strClassName ) {
	var tempFun = function() {
		var elementArr = strClassName ? getElementsByClassName(oElm , strTagName , strClassName) : oElm.getElementsByTagName(strTagName)  ;
		tfish(elementArr) ;
	}
	if(extra && window.attachEvent) {
		window.attachEvent("onload", tempFun);
	}
	else if (extra && window.addEventListener) {
		window.addEventListener('load' , tempFun , false);
	}

}
var ku6focus = function(iptArr) {
	for (var i=0; i < iptArr.length; i++) {
		if(iptArr[i].type == 'checkbox' || iptArr[i].type == 'radio'){
			continue;
		}
		iptArr[i].attachEvent("onfocus" , function(evt) {
		   element = returnEventValue('srcElement' , evt)
		   removeClassName(element , 'ku6nofocus') ;
		   addClassName(element , 'ku6focus') ;
		}) ;
		iptArr[i].attachEvent("onblur", function(evt) {
		   element = returnEventValue('srcElement' , evt)
		   removeClassName(element , 'ku6focus');
		   removeClassName(element , 'ku6error');
		   addClassName(element , 'ku6nofocus');
		}) ;
	}
}
applefish( browser.msie , ku6focus, "input" , document );
applefish( browser.msie , ku6focus, "select" , document );
applefish( browser.msie , ku6focus, "textarea" , document );

function returnEventValue (type , evt) {
	return evt.srcElement ? evt.srcElement : evt.target ;
}